//    Copyright (C) Kherty.  All rights reserved.
using OpenLS.Core;
using OpenLS.Spreadsheet.Internals;

namespace OpenLS.Spreadsheet
{
    class RowHeightUndoUnitContainer : CompositeUndoUnit
    {
        public RowHeightUndoUnitContainer(Row row): base (StringTable.RowHeight)
        {
            _row = row;
        }

        readonly Row _row;
        internal override ICompositeUndoUnit GetEmptyClone()
        {
            return new RowHeightUndoUnitContainer(_row);
        }
        public override bool Merge(IUndoUnit unit)
        {
            if (unit is RowHeightUndoUnitContainer)
            {
                RowHeightUndoUnitContainer u = (RowHeightUndoUnitContainer)unit;
                if (u.Children.Count != 1)
                    return false;
                if (Children.Count != 1)
                    return false;
                RowHeightUndoUnit u1 = Children.Peek() as RowHeightUndoUnit;
                RowHeightUndoUnit u2 = u.Children.Peek() as RowHeightUndoUnit;
                if (u1 == null || u2 == null)
                    return false;
                return _row == u._row;
            }
            return false;
        }
    }
}